package mest.controller.LGF.FinancialPurchaseMoney;

import mest.VO.LGF.FinancialPurchaseMoney.financial_PurchaseMoneyRecordVO;
import mest.entity.User;
import mest.service.LGF.FinancialPurchaseMoney.IFinancialPurchaseMoneyService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Description
 * @auther Machenike
 * @create 2019-12-19 17:05
 */
//Model是属于请求域
    //           @RequestMapping(value="/one",params = "method=a")
   //           @RequestMapping(value="/two1",produces = {"application/json;charset=utf-8","text/plain;charset=utf-8"})
    //参数:@RequestParam(value = "b",required = false,defaultValue = "握草尼玛")
    //         @RequestBody String(str) 输出:userCode=admin&userPassword=1234567
    //          @SessionAttributes({"a","b","c"}) 自动把该controller下所有返回页面的属性的作用域改成session
    //          @ModelAttribute标注一个方法时，指定每次跳入某个路径时该方法先执行
@CrossOrigin
@RestController
@RequestMapping(value="/financial_PurchaseMoney")
public class FinancialPurchaseMoneyController {

    @Resource
    private IFinancialPurchaseMoneyService ifpms;

    @RequestMapping(value="/baseSelectNofinish", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public Map baseSelectNofinish(int page, int limit){
        Map map = ifpms.baseSelectNofinish(page, limit);
        return map;
    }


    @RequestMapping(value="/baseSelectFinish", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public Map baseSelectFinish(int page,int limit){
        Map map = ifpms.baseSelectFinish(page, limit);
        return map;
    }

    @RequestMapping(value="/baseSelectAccountFile", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public Map baseSelectAccountFile(int page,int limit){
        Map map = ifpms.baseSelectAccountFile(page, limit);
        return map;
    }
    @RequestMapping(value="/baseSelectSubjectType", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public Map baseSelectSubjectType(int page,int limit){
        Map map = ifpms.baseSelectSubjectType(page, limit);
        return map;
    }
    @RequestMapping(value="/addRecord", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String addRecord(financial_PurchaseMoneyRecordVO fpmrVO, HttpServletRequest req){

        User user = (User) req.getSession().getAttribute("user");
        fpmrVO.setEfId(user.getUserId());

        int i = ifpms.addFinancialRecord(fpmrVO);

        if(i == -2){
            return   "服务器异常";
        }else if(i == -1){
            return "插入失败";
        }else if(i>0){
            return "插入成功";
        }

        return "未知错误，请联系管理员";
    }

    @RequestMapping(value="/pastRecord", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public Map pastRecord(int fpmId,int page,int limit){
        Map map = ifpms.selectPastRecord(fpmId,page,limit);
        return map;
    }


    @RequestMapping(value="/finish", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String finish(int fpmId,int status){

        int i = ifpms.updateByFPMId(fpmId, status);
        if(i == -2){
            return   "服务器异常";
        }else if(i == -1){
            return "更新失败";
        }else if(i>0){
            return "更新成功";
        }
        return "未知错误，请联系管理员";
    }

    @RequestMapping(value="/nofinish", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String nofinish(int  fpmId,int status){

        int i = ifpms.updateByFPMId(fpmId, status);
        if(i == -2){
            return   "服务器异常";
        }else if(i == -1){
            return "更新失败";
        }else if(i>0){
            return "更新成功";
        }
        return "未知错误，请联系管理员";
    }
}
